package jee.boot.entity.mail;

import com.fasterxml.jackson.annotation.JsonFormat;
import jee.boot.common.annotation.Column;
import jee.boot.common.annotation.Table;
import jee.boot.common.annotation.Transient;
import jee.boot.common.basic.DataEntity;
import jee.boot.entity.auth.Account;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 邮件发送Entity
 *
 * @author zhilei.wang
 * @version 2018-09-28
 */
@Table(name = "st_mail")
public class Mail extends DataEntity<Mail> {
    /**
     * 发送人
     */
    private String fromMail;
    /**
     * 收件人
     */
    private String toMail;
    /**
     * 抄送人
     */
    private String ccMail;
    /**
     * 暗送人
     */
    private String bccMail;
    /**
     * 发送时间
     */
    private Date sentDate;
    /**
     * 主题
     */
    private String subject;
    /**
     * 邮件内容
     */
    private String text;
    /**
     * 发送状态
     */
    private String sendStatus;
    /**
     * 发送信息
     */
    private String message;
    /**
     * 发送人
     */
    @Column(name = "send_user_id", data = {"sendUser.id", "sendUser.username"})
    private Account sendUser;
    /**
     * 附件
     */
    @Transient
    /**
     * 附件文件不进行数据库存储
     */
    private List<File> attachmentList = new ArrayList<>();
    @Transient
    /**
     * 邮件是否使用的模板(选填)
     */
    private String templateName;
    @Transient
    /**
     * 邮件使用模板时候使用的(选填)
     */
    private Map<String, Object> data;
    @Transient
    /**
     * 默认异步发送
     */
    private boolean asyn = true;

    // 以下为日历邮件特殊属性，不保存数据库
    /**
     * 地点信息
     */
    @Transient
    private String location;
    /**
     * 开始时间
     */
    @Transient
    private Date startDateTime;
    /**
     * 结束时间
     */
    @Transient
    private Date endDateTime;

    public String getFromMail() {
        return fromMail;
    }

    public void setFromMail(String fromMail) {
        this.fromMail = fromMail;
    }

    public String getToMail() {
        return toMail;
    }

    public void setToMail(String toMail) {
        this.toMail = toMail;
    }

    public String getCcMail() {
        return ccMail;
    }

    public void setCcMail(String ccMail) {
        this.ccMail = ccMail;
    }

    public String getBccMail() {
        return bccMail;
    }

    public void setBccMail(String bccMail) {
        this.bccMail = bccMail;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getSentDate() {
        return sentDate;
    }

    public void setSentDate(Date sentDate) {
        this.sentDate = sentDate;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getSendStatus() {
        return sendStatus;
    }

    public void setSendStatus(String sendStatus) {
        this.sendStatus = sendStatus;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Account getSendUser() {
        return sendUser;
    }

    public void setSendUser(Account sendUser) {
        this.sendUser = sendUser;
    }

    public List<File> getAttachmentList() {
        return attachmentList;
    }

    public void setAttachmentList(List<File> attachmentList) {
        this.attachmentList = attachmentList;
    }

    public String getTemplateName() {
        return templateName;
    }

    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public boolean isAsyn() {
        return asyn;
    }

    public void setAsyn(boolean asyn) {
        this.asyn = asyn;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public Date getStartDateTime() {
        return startDateTime;
    }

    public void setStartDateTime(Date startDateTime) {
        this.startDateTime = startDateTime;
    }

    public Date getEndDateTime() {
        return endDateTime;
    }

    public void setEndDateTime(Date endDateTime) {
        this.endDateTime = endDateTime;
    }

    @Override
    public String toString() {
        return getFromMail() + "->[" + getToMail() + ",cc:" + getCcMail() + ",bcc:" + getBccMail() + "],subject:" + getSubject();
    }
}
